<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>用户名验证</title>
    <style>
      .error {
        font-weight: bolder;
        color: red;
      }

      .ok {
        color: green;
      }
    </style>
  </head>
  <body>
    <input type="text" id="username" /><span id="usernameHint"></span>

    <script>
      const names = ['admin', 'zs', 'ls']
      username.onblur = function () {
        if (names.includes(this.value)) {
          usernameHint.innerHTML = '该用户名已经存在'
          usernameHint.className = 'error'
        } else {
          usernameHint.innerHTML = 'OK'
          usernameHint.className = 'ok'
        }
      }
    </script>
  </body>
</html>
